#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main()
{
	int N = 0;
	scanf("%d", &N);
	int a = 0;
	int b = 1;
	int i = 0;
	for (i = 0; b <= N; i++)
	{
		int c= a + b;
		a = b;
		b = c;
		if (N == a)
		{
			printf("0");
			break;
		}
	}
	if (b > N)
	{
		int d=(N - a) < (b - N) ? (N - a) : (b-N);
		printf("%d", d);
	}
	return 0;
}